Fix several problems with this function. (fd.o #9560, Yevgen Muntyan)
authorMatthias Clasen <mclasen@redhat.com>
Mon, 8 Jan 2007 03:39:41 +0000 (03:39 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 8 Jan 2007 03:39:41 +0000 (03:39 +0000)
2007-01-07  Matthias Clasen  <mclasen@redhat.com>

        * xdgmimecache.c (_xdg_mime_cache_list_mime_parents): Fix
        several problems with this function.  (fd.o #9560, Yevgen Muntyan)

svn path=/trunk/; revision=17110

gtk/xdgmime/ChangeLog
gtk/xdgmime/xdgmimecache.c

index b4a4b9b292d3f770f741dea6d8aa1fcfb0934512..9b4f106f18059d8cb6fe50f94115844bdbcdfbd8 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-07  Matthias Clasen  <mclasen@redhat.com>
+
+       * xdgmimecache.c (_xdg_mime_cache_list_mime_parents): Fix 
+       several problems with this function.  (fd.o #9560, Yevgen Muntyan)
+
 2006-08-17  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.10.2 ===
index d08c89b1cd71b588fd3ccf28d6e31036389bfe9c..a8035798d4acb5b318f9e3c443a27c954d7c6a05 100644 (file)
@@ -850,10 +850,12 @@ _xdg_mime_cache_unalias_mime_type (const char *mime)
 char **
 _xdg_mime_cache_list_mime_parents (const char *mime)
 {
-  int i, j, p;
+  int i, j, k, p;
   char *all_parents[128]; /* we'll stop at 128 */ 
   char **result;
 
+  mime = xdg_mime_unalias_mime_type (mime);
+
   p = 0;
   for (i = 0; _caches[i]; i++)
     {
@@ -864,15 +866,19 @@ _xdg_mime_cache_list_mime_parents (const char *mime)
 
       for (j = 0; j < n_entries; j++)
        {
-         xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * i);
-         xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * i + 4);
-         
+         xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j);
+         xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j + 4);
+
          if (strcmp (cache->buffer + mimetype_offset, mime) == 0)
            {
+             xdg_uint32_t parent_mime_offset;
              xdg_uint32_t n_parents = GET_UINT32 (cache->buffer, parents_offset);
-             
-             for (j = 0; j < n_parents; j++)
-               all_parents[p++] = cache->buffer + parents_offset + 4 + 4 * j;
+
+             for (k = 0; k < n_parents && p < 127; k++)
+               {
+                 parent_mime_offset = GET_UINT32 (cache->buffer, parents_offset + 4 + 4 * k);
+                 all_parents[p++] = cache->buffer + parent_mime_offset;
+               }
 
              break;
            }